<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.*"%>

<%
    String path = request.getContextPath();
    String ctx = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
    String wctx = request.getServerName()+":"+request.getServerPort()+path;
%>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="<%=ctx%>/websocket/jquery-1.12.3.min.js" ></script>
    <script type="text/javascript" src="<%=ctx%>/websocket/bootstrap.min.js" ></script>
    <link rel="stylesheet" href="<%=ctx%>/websocket/bootstrap.min.css" />
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        html,body {
            width: 100%;
            height: 100%;
            overflow: hidden;
            background-color: #FFFFFF;
            font-family: "Microsoft YaHei", sans-serif;
        }
    </style>
</head>
<body>
<table border="0" style="width: 100%;height: 100%">
    <tr>
        <td style="width:400px;height: 100%">
            <table border="0" style="width: 100%;height: 100%">
                <tr>
                    <td height="*" align="center">
                        <div class="panel panel-primary" style="height: 100%;width:100%;margin-bottom:0px;border-color:#102146;">
                            <div class="panel-heading" style="background-color: #273655;border-color: #273655;">
                                <h3 class="panel-title">文件列表</h3>
                            </div>
                            <div class="panel-body" style="margin-bottom:0px;padding: 1px;">
                                <table class="table table-bordered mytable" style="margin-bottom:0px">
                                    <thead>
                                    <tr>
                                        <th class="text-center">文件名称</th>
                                        <th class="text-center" style="width: 80px">上传人</th>
                                        <%--<th>上传时间</th>--%>
                                        <th style="width: 100px"></th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                        <c:forEach items="${filelist}" varStatus="i" var="item" >
                                            <tr>
                                                <td style="padding: 1px;font-size: small;">${item.filename}</td>
                                                <td class="text-center" style="padding: 1px;font-size: small;">${item.username}</td>
                                                <%--<td>${item.mdate}</td>--%>
                                                <td class="text-center" style="padding: 1px;font-size: small;">
                                                    <a href="#" onclick="fileview('${item.fullname}');">预览</a>
                                                    <a href="<%=ctx%>/file/download?fileName=${item.fullname}">下载</a>
                                                    <a href="#" onclick="delefile('${item.fullname}');">删除</a></td>
                                            </tr>
                                        </c:forEach>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td height="70" align="center" style="border:1px solid #102146">
                        <form action="<%=ctx%>/file/upload" method="post" enctype="multipart/form-data">
                            <input type="hidden" name="username">
                            <div class="form-group">
                                <input type="file" id="file" name="file" style="display: inline">
                                <button type="submit" class="btn btn-default">上传</button>
                            </div>
                        </form>
                    </td>
                </tr>
            </table>
        </td>
        <td align="center" style="border:1px solid #102146;height:100%">
            <iframe src="<%=ctx%>/file/view" id="fileFrame" name="fileFrame" frameborder="0" width="100%" height="100%" frameBorder="0" style="height:100%"></iframe>
        </td>
    </tr>
</table>
<script>
    function delefile(filename){
        $.post("<%=ctx%>/file/delefile",{"fileName":filename},function(data){
            location.reload();
        });
    }
    function fileview(filename){
        ///$("#fileFrame").src="<%=ctx%>/file/view?filename="+filename;
        $('#fileFrame').attr('src', '<%=ctx%>/file/view?filename='+filename);
        //window.open('<%=ctx%>/file/view?filename='+filename);
    }

</script>
</body>
</html>
